package com.ncloud.crm.mapper;

import org.apache.ibatis.annotations.*;

import com.ncloud.crm.entity.order.WorkNodeEqpt;

import java.util.List;

/**
 * Created by shiqiang on 2017/4/11.
 */
@Mapper
public interface WorkNodeEqptMapper {
    @Select(value = { "select * from bs_o_work_eqpt where work_id = #{workId}" })
    @Results({ @Result(column = "work_id", property = "workId"), 
    		@Result(column = "modify_tag", property = "modifyTag"),
            @Result(column = "node_id", property = "nodeId"),
            @Result(column = "eqpt_id", property = "eqptId"),@Result(column="post_address",property="postAddress"),
            @Result(column="uses_address",property="usesAddress"),@Result(column="contact_name",property="contactName"),
            @Result(column="contact_phone",property="contactPhone"),@Result(column="manage_ip",property="manageIp"),
            @Result(column="begin_date",property="beginDate"),@Result(column="end_date",property="endDate"),
            @Result(column="update_time",property="updateTime"),@Result(column="update_user",property="updateUser"),
            @Result(column="province",property="province"),@Result(column="city",property="city")
    })
    public List<WorkNodeEqpt> getWorkNodeEqptByWorkId(Long workId);
    @Insert(value = "insert into bs_o_work_eqpt(work_id,modify_tag,node_id,eqpt_id,uses_address, post_address,contact_name,contact_phone," +
            "manage_ip,begin_date,end_date,update_time,update_user, province, city) values(#{workId},#{modifyTag},#{nodeId},#{eqptId}," +
            "#{usesAddress},#{postAddress},#{contactName},#{contactPhone},#{manageIp},#{beginDate},#{endDate},#{updateTime},#{updateUser}, #{province}, #{city})")
    public int insertWorkNodeEqpt(WorkNodeEqpt workNodeEqpt);
    
	@Select(value = {"select #{workId} as work_id,eqpt_id,node_id,uses_address,post_address,contact_name,contact_phone,manage_ip from bs_eqpt_info"
					+ " where node_id = #{nodeId} and NOW() BETWEEN begin_date and end_date and eqpt_id not in ("
					+ " select eqpt_id from bs_o_work_eqpt where work_id = #{workId} and modify_tag='3')" + " UNION "
					+ " select work_id,eqpt_id,node_id,uses_address,post_address,contact_name,contact_phone,manage_ip from bs_o_work_eqpt"
					+ "  where work_id = #{workId} and modify_tag='1'" })
    @Results({ @Result(column = "work_id", property = "workId"),
            @Result(column = "node_id", property = "nodeId"),
            @Result(column = "eqpt_id", property = "eqptId"),@Result(column="uses_address",property="usesAddress"),
            @Result(column="post_address",property="postAddress"),@Result(column="contact_name",property="contactName"),
            @Result(column="contact_phone",property="contactPhone"),@Result(column="manage_ip",property="manageIp"),
            @Result(column="province",property="province"),@Result(column="city",property="city")})
	public List<WorkNodeEqpt> getNewNodeEqptsByWorkId(@Param("workId")Long workId, @Param("nodeId")Long nodeId);
}
